package com.controller;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.entity.Dayi;
import com.entity.Course;
import com.entity.Lilun;
import com.entity.Shipin;
import com.entity.Shiyan;
import com.entity.User;
import com.entity.Ziyuan;
import com.service.DayiService;
import com.service.KechengService;
import com.service.LilunService;
import com.service.ShipinService;
import com.service.ShiyanService;
import com.service.UserService;
import com.service.ZiyuanService;
import com.util.Util;



@Controller
@RequestMapping("/manage")
public class ManageController {

	@Resource
	private UserService userService;

	@Resource
	private KechengService kechengService;
	
	@Resource
	private LilunService lilunService;
	
	@Resource
	private ShiyanService shiyanService;
	
	@Resource
	private ZiyuanService ziyuanService;
	
	@Resource
	private ShipinService shipinService;
	
	@Resource
	private DayiService dayiService;
	
	
	
	@Value("#{jdbc.pageSize}")
	private int pageSize;


	// 获取输出对象
	public PrintWriter getPrintWriter(HttpServletResponse response) {
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf-8");
		PrintWriter writer = null;
		try {
			writer = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return writer;
	}



	//管理员登录
	@RequestMapping("/login.do")
	public void login(HttpServletRequest request,HttpServletResponse response,String username,String password){

		PrintWriter writer = this.getPrintWriter(response);

		User user = userService.userlogin(username, password,1);

		if(user==null){

			writer.print("<script language=javascript>alert('用户名或者密码错误');window.location.href='login.jsp';</script>");

		}else{
			HttpSession session = request.getSession();
			session.setAttribute("manage", user);

			writer.print("<script language=javascript>alert('登录成功');window.location.href='index.jsp';</script>");

		}

	}


	//安全退出
	@RequestMapping("/loginout.do")
	public void loginout(HttpServletRequest request,HttpServletResponse response,String username,String password){

		
		PrintWriter writer = this.getPrintWriter(response);

		HttpSession session = request.getSession();
		session.removeAttribute("manage");
		writer.print("<script language=javascript>alert('退出成功');window.location.href='login.jsp';</script>");

	}


	//跳转到修改密码页面
	@RequestMapping("/password.do")
	public String password(HttpServletRequest request){

		request.setAttribute("url", "password2.do");

		request.setAttribute("title", "修改密码");

		return "password.jsp";

	}

	//修改密码操作
	@RequestMapping("/password2.do")
	public void password2(HttpServletRequest request,HttpServletResponse response,String password1,String password2){

		PrintWriter writer = this.getPrintWriter(response);

		HttpSession session = request.getSession();

		User user = (User)session.getAttribute("manage");

		User bean = userService.userlogin(user.getUsername(), password1, user.getRole());

		if(bean!=null){
			bean.setPassword(password2);
			userService.updateBean(bean);

			writer.print("<script language=javascript>alert('修改成功');window.location.href='password.do';</script>");


		}else{

			writer.print("<script language=javascript>alert('用户名或者密码错误');window.location.href='password.do';</script>");

		}
	}

	
	
	//教学课程列表
	@RequestMapping("/kechenglist.do")
	public String kechenglist(HttpServletRequest request,String pagenum,String kname){

		String url = "kechenglist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_kecheng where  ");
		
		//查询条件返回页面
		if (kname != null && !"".equals(kname)) {

			sb.append(" kname like '%"+kname+"%' ");
			sb.append(" and ");
			
			request.setAttribute("kname", kname);
		}
		

		sb.append(" 1=1 order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Course>> map = kechengService.selectBeanMap(currentpage,pageSize,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Course> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);

		//添加，更新，删除等按钮
		request.setAttribute("url2", "kecheng");

		request.setAttribute("title", "教学课程管理");


		return "kecheng/kechenglist.jsp";

	}


	//跳转到添加教学课程页面
	@RequestMapping("/kechengadd.do")
	public String kechengadd(HttpServletRequest request){

		request.setAttribute("url", "kechengadd2.do");

		request.setAttribute("title", "添加教学课程");

		return "kecheng/kechengadd.jsp";

	}


	//添加教学课程操作
	@RequestMapping("/kechengadd2.do")
	public void kechengadd2(HttpServletRequest request,HttpServletResponse response,Course bean){
		
		
		kechengService.insertBean(bean);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='kechenglist.do';</script>");
	}


	//跳转到修改教学课程页面
	@RequestMapping("/kechengupdate.do")
	public String kechengupdate(HttpServletRequest request,int id){

		Course bean = kechengService.selectData(" select * from t_kecheng where id= "+id).get(0);
		
		request.setAttribute("bean", bean);

		request.setAttribute("url", "kechengupdate2.do?id="+id);
		
		request.setAttribute("title", "修改教学课程");

		return "kecheng/kechengupdate.jsp";

	}

	//修改教学课程操作
	@RequestMapping("/kechengupdate2.do")
	public void kechengupdate2(HttpServletRequest request,HttpServletResponse response,Course bean){

		
		kechengService.updateBean(bean);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='kechenglist.do';</script>");
	}


	//删除操作
	@RequestMapping("/kechengdelete.do")
	public void kechengdelete(HttpServletResponse response,int id){

		kechengService.deleteBean(id);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='kechenglist.do';</script>");
	}



	//跳转到查看详情页面
	@RequestMapping("/kechengshow.do")
	public String kechengshow(HttpServletRequest request,int id){

		Course bean = kechengService.selectData(" select * from t_kecheng where id= "+id).get(0);

		request.setAttribute("bean", bean);

		request.setAttribute("title", "查看详情");

		return "kecheng/kechengshow.jsp";

	}
	
	
	
	
	//理论教学列表
//	@RequestMapping("/lilunlist.do")
//	public String lilunlist(HttpServletRequest request,String pagenum,String biaoti){
//
//		String url = "lilunlist.do";//当前访问的地址
//		
//		//默认第一页
//		int currentpage = 1;
//		//获取当前页
//		if (pagenum != null) {
//			currentpage = Integer.parseInt(pagenum);
//		}
//		
//		//组装查询的sql语句
//		StringBuffer sb = new StringBuffer();
//		
//		sb.append(" select * from t_lilun where  ");
//		
//		//查询条件返回页面
//		if (biaoti != null && !"".equals(biaoti)) {
//
//			sb.append(" biaoti like '%"+biaoti+"%' ");
//			sb.append(" and ");
//			
//			request.setAttribute("biaoti", biaoti);
//		}
//		
//
//		sb.append(" 1=1 order by id desc ");
//		
//		String sql = sb.toString();
//		
//
//		//查询列表
//		Map<String,List<Lilun>> map = lilunService.selectBeanMap(currentpage,pageSize,url,sql);
//		String pagerinfo = map.keySet().iterator().next();
//		List<Lilun> list = map.get(pagerinfo);
//
//		//列表返回页面
//		request.setAttribute("list", list);
//
//		//分页信息返回页面
//		request.setAttribute("pagerinfo", pagerinfo);
//
//		//查询按钮
//		request.setAttribute("url", url);
//
//		//添加，更新，删除等按钮
//		request.setAttribute("url2", "lilun");
//
//		request.setAttribute("title", "理论教学管理");
//
//
//		return "lilun/lilunlist.jsp";
//
//	}
//
//
//	//跳转到添加理论教学页面
//	@RequestMapping("/lilunadd.do")
//	public String lilunadd(HttpServletRequest request){
//
//		request.setAttribute("url", "lilunadd2.do");
//
//		request.setAttribute("title", "添加理论教学");
//
//		request.setAttribute("kechenglist", kechengService.selectData(" select * from t_kecheng "));
//		
//		return "lilun/lilunadd.jsp";
//
//	}
//
//
//	//添加理论教学操作
//	@RequestMapping("/lilunadd2.do")
//	public void lilunadd2(HttpServletRequest request,HttpServletResponse response,Lilun bean){
//		
//		
//		Course kecheng = kechengService.selectData(" select * from t_kecheng where id= "+bean.getKechengid()).get(0);
//		
//		bean.setCtime(Util.getRiqi());
//		bean.setKname(kecheng.getKname());
//		bean.setVist(0);
//		
//		lilunService.insertBean(bean);
//
//
//		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='lilunlist.do';</script>");
//	}
//
//
//	//跳转到修改理论教学页面
//	@RequestMapping("/lilunupdate.do")
//	public String lilunupdate(HttpServletRequest request,int id){
//
//		Lilun bean = lilunService.selectData(" select * from t_lilun where id= "+id).get(0);
//		
//		request.setAttribute("bean", bean);
//
//		request.setAttribute("url", "lilunupdate2.do?id="+id);
//		
//		request.setAttribute("title", "修改理论教学");
//
//		request.setAttribute("kechenglist", kechengService.selectData(" select * from t_kecheng "));
//		
//		return "lilun/lilunupdate.jsp";
//
//	}
//
//	//修改理论教学操作
//	@RequestMapping("/lilunupdate2.do")
//	public void lilunupdate2(HttpServletRequest request,HttpServletResponse response,Lilun bean){
//
//		Course kecheng = kechengService.selectData(" select * from t_kecheng where id= "+bean.getKechengid()).get(0);
//		
//		bean.setKname(kecheng.getKname());
//		
//		lilunService.updateBean(bean);
//
//
//		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='lilunlist.do';</script>");
//	}
//
//
//	//删除操作
//	@RequestMapping("/lilundelete.do")
//	public void lilundelete(HttpServletResponse response,int id){
//
//		lilunService.deleteBean(id);
//
//
//		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='lilunlist.do';</script>");
//	}
//
//
//
//	//跳转到查看详情页面
//	@RequestMapping("/lilunshow.do")
//	public String lilunshow(HttpServletRequest request,int id){
//
//		Lilun bean = lilunService.selectData(" select * from t_lilun where id= "+id).get(0);
//
//		request.setAttribute("bean", bean);
//
//		request.setAttribute("title", "查看详情");
//
//		return "lilun/lilunshow.jsp";
//
//	}
//	
//	
//	
	//实验教学列表
	@RequestMapping("/shiyanlist.do")
	public String shiyanlist(HttpServletRequest request,String pagenum,String biaoti){

		String url = "shiyanlist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_shiyan where  ");
		
		//查询条件返回页面
		if (biaoti != null && !"".equals(biaoti)) {

			sb.append(" biaoti like '%"+biaoti+"%' ");
			sb.append(" and ");
			
			request.setAttribute("biaoti", biaoti);
		}
		

		sb.append(" 1=1 order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Shiyan>> map = shiyanService.selectBeanMap(currentpage,pageSize,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Shiyan> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);

		//添加，更新，删除等按钮
		request.setAttribute("url2", "shiyan");

		request.setAttribute("title", "实验教学管理");


		return "shiyan/shiyanlist.jsp";

	}


	//跳转到添加实验教学页面
	@RequestMapping("/shiyanadd.do")
	public String shiyanadd(HttpServletRequest request){

		request.setAttribute("url", "shiyanadd2.do");

		request.setAttribute("title", "添加实验教学");

		request.setAttribute("kechenglist", kechengService.selectData(" select * from t_kecheng "));
		
		return "shiyan/shiyanadd.jsp";

	}


	//添加实验教学操作
//	@RequestMapping("/shiyanadd2.do")
//	public void shiyanadd2(HttpServletRequest request,HttpServletResponse response,Shiyan bean){
//		
//		
//		Course kecheng = kechengService.selectData(" select * from t_kecheng where id= "+bean.getKechengid()).get(0);
//		
//		bean.setCtime(Util.getRiqi());
//		bean.setKname(kecheng.getKname());
//		bean.setVist(0);
//		
//		shiyanService.insertBean(bean);
//
//
//		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='shiyanlist.do';</script>");
//	}
//
//
//	//跳转到修改实验教学页面
//	@RequestMapping("/shiyanupdate.do")
//	public String shiyanupdate(HttpServletRequest request,int id){
//
//		Shiyan bean = shiyanService.selectData(" select * from t_shiyan where id= "+id).get(0);
//		
//		request.setAttribute("bean", bean);
//
//		request.setAttribute("url", "shiyanupdate2.do?id="+id);
//		
//		request.setAttribute("title", "修改实验教学");
//
//		request.setAttribute("kechenglist", kechengService.selectData(" select * from t_kecheng "));
//		
//		return "shiyan/shiyanupdate.jsp";
//
//	}
//
//	//修改实验教学操作
//	@RequestMapping("/shiyanupdate2.do")
//	public void shiyanupdate2(HttpServletRequest request,HttpServletResponse response,Shiyan bean){
//
//		Course kecheng = kechengService.selectData(" select * from t_kecheng where id= "+bean.getKechengid()).get(0);
//		
//		bean.setKname(kecheng.getKname());
//		
//		shiyanService.updateBean(bean);
//
//
//		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='shiyanlist.do';</script>");
//	}
//
//
//	//删除操作
//	@RequestMapping("/shiyandelete.do")
//	public void shiyandelete(HttpServletResponse response,int id){
//
//		shiyanService.deleteBean(id);
//
//
//		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='shiyanlist.do';</script>");
//	}
//
//
//
//	//跳转到查看详情页面
//	@RequestMapping("/shiyanshow.do")
//	public String shiyanshow(HttpServletRequest request,int id){
//
//		Shiyan bean = shiyanService.selectData(" select * from t_shiyan where id= "+id).get(0);
//
//		request.setAttribute("bean", bean);
//
//		request.setAttribute("title", "查看详情");
//
//		return "shiyan/shiyanshow.jsp";
//
//	}
//	
//	
//	
	//教师列表
	@RequestMapping("/userlist.do")
	public String userlist(HttpServletRequest request,String pagenum,String username){

		String url = "userlist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_user where  ");
		
		//查询条件返回页面
		if (username != null && !"".equals(username)) {

			sb.append(" username like '%"+username+"%' ");
			sb.append(" and ");
			
			request.setAttribute("username", username);
		}
		

		sb.append(" role=2 order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<User>> map = userService.selectBeanMap(currentpage,pageSize,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<User> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);

		//添加，更新，删除等按钮
		request.setAttribute("url2", "user");

		request.setAttribute("title", "教师管理");


		return "user/userlist.jsp";

	}


	//跳转到添加教师页面
	@RequestMapping("/useradd.do")
	public String useradd(HttpServletRequest request){

		request.setAttribute("url", "useradd2.do");

		request.setAttribute("title", "添加教师");

		request.setAttribute("kechenglist", kechengService.selectData(" select * from t_kecheng "));
		
		return "user/useradd.jsp";

	}


	//添加教师操作
	@RequestMapping("/useradd2.do")
	public void useradd2(HttpServletRequest request,HttpServletResponse response,User bean){
		
		User uu = userService.useryz(bean.getUsername());
		
		if(uu!=null){
			
			this.getPrintWriter(response).print("<script language=javascript>alert('该用户名已经存在，添加失败！');window.location.href='userlist.do';</script>");
		
			return;	
		}
		
		Course kecheng = kechengService.selectData(" select * from t_kecheng where id= "+bean.getKechengid()).get(0);
		
		bean.setCtime(Util.getRiqi());
		//bean.setKname(course.getname());
		
		bean.setPassword("111111");
		bean.setRole(2);
		
		userService.insertBean(bean);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='userlist.do';</script>");
	}


	//跳转到修改教师页面
	@RequestMapping("/userupdate.do")
	public String userupdate(HttpServletRequest request,int id){

		User bean = userService.selectBeanById(id);
		
		request.setAttribute("bean", bean);

		request.setAttribute("url", "userupdate2.do?id="+id);
		
		request.setAttribute("title", "修改教师信息");

		request.setAttribute("kechenglist", kechengService.selectData(" select * from t_kecheng "));
		
		return "user/userupdate.jsp";

	}

	//修改教师操作
	@RequestMapping("/userupdate2.do")
	public void userupdate2(HttpServletRequest request,HttpServletResponse response,User bean){

		Course kecheng = kechengService.selectData(" select * from t_kecheng where id= "+bean.getKechengid()).get(0);
		
		//bean.setKname(kecheng.getKname());
		
		bean.setRole(2);
		
		userService.updateBean(bean);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='userlist.do';</script>");
	}


	//删除操作
	@RequestMapping("/userdelete.do")
	public void userdelete(HttpServletResponse response,int id){

		userService.deleteBean(id);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='userlist.do';</script>");
	}



	//跳转到查看详情页面
	@RequestMapping("/usershow.do")
	public String usershow(HttpServletRequest request,int id){

		User bean = userService.selectBeanById(id);

		request.setAttribute("bean", bean);

		request.setAttribute("title", "查看详情");

		return "user/usershow.jsp";

	}
	

	//学生列表
	@RequestMapping("/userlist2.do")
	public String userlist2(HttpServletRequest request,String pagenum,String username){

		String url = "userlist2.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_user where  ");
		
		//查询条件返回页面
		if (username != null && !"".equals(username)) {

			sb.append(" username like '%"+username+"%' ");
			sb.append(" and ");
			
			request.setAttribute("username", username);
		}
		

		sb.append(" role=3 order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<User>> map = userService.selectBeanMap(currentpage,pageSize,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<User> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);

		//添加，更新，删除等按钮
		request.setAttribute("url2", "user");

		request.setAttribute("title", "学生管理");


		return "user/userlist2.jsp";

	}


	

	//删除操作
	@RequestMapping("/userdelete2.do")
	public void userdelete2(HttpServletResponse response,int id){

		userService.deleteBean(id);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='userlist2.do';</script>");
	}
	
	
	
	
	
	

	//教学资源列表
	@RequestMapping("/ziyuanlist.do")
	public String ziyuanlist(HttpServletRequest request,String pagenum,String zname){

		String url = "ziyuanlist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_ziyuan where  ");
		
		//查询条件返回页面
		if (zname != null && !"".equals(zname)) {

			sb.append(" zname like '%"+zname+"%' ");
			sb.append(" and ");
			
			request.setAttribute("zname", zname);
		}
		

		sb.append(" 1=1 order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Ziyuan>> map = ziyuanService.selectBeanMap(currentpage,pageSize,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Ziyuan> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);

		//添加，更新，删除等按钮
		request.setAttribute("url2", "ziyuan");

		request.setAttribute("title", "教学资源管理");


		return "ziyuan/ziyuanlist.jsp";

	}


	

	//删除操作
	@RequestMapping("/ziyuandelete.do")
	public void ziyuandelete(HttpServletResponse response,int id){

		ziyuanService.deleteBean(id);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='ziyuanlist.do';</script>");
	}
	
	
	//跳转到查看详情页面
	@RequestMapping("/ziyuanshow.do")
	public String ziyuanshow(HttpServletRequest request,int id){

		Ziyuan bean = ziyuanService.selectData(" select * from t_ziyuan where id= "+id).get(0);

		request.setAttribute("bean", bean);

		request.setAttribute("title", "查看详情");

		return "ziyuan/ziyuanshow.jsp";

	}
	
	
	
	//教学视频列表
	@RequestMapping("/shipinlist.do")
	public String shipinlist(HttpServletRequest request,String pagenum,String sname){

		String url = "shipinlist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_shipin where  ");
		
		//查询条件返回页面
		if (sname != null && !"".equals(sname)) {

			sb.append(" sname like '%"+sname+"%' ");
			sb.append(" and ");
			
			request.setAttribute("sname", sname);
		}
		

		sb.append(" 1=1 order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Shipin>> map = shipinService.selectBeanMap(currentpage,pageSize,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Shipin> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);

		//添加，更新，删除等按钮
		request.setAttribute("url2", "shipin");

		request.setAttribute("title", "教学视频管理");


		return "shipin/shipinlist.jsp";

	}


	

	//删除操作
	@RequestMapping("/shipindelete.do")
	public void shipindelete(HttpServletResponse response,int id){

		shipinService.deleteBean(id);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='shipinlist.do';</script>");
	}
	
	
	//跳转到查看详情页面
	@RequestMapping("/shipinshow.do")
	public String shipinshow(HttpServletRequest request,int id){

		Shipin bean = shipinService.selectData(" select * from t_shipin where id= "+id).get(0);

		request.setAttribute("bean", bean);

		request.setAttribute("title", "查看详情");

		return "shipin/shipinshow.jsp";

	}
	
	
	
	//在线答疑列表
	@RequestMapping("/dayilist.do")
	public String dayilist(HttpServletRequest request,String pagenum,String dbiaoti){

		String url = "dayilist.do";//当前访问的地址
		
		//默认第一页
		int currentpage = 1;
		//获取当前页
		if (pagenum != null) {
			currentpage = Integer.parseInt(pagenum);
		}
		
		//组装查询的sql语句
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select * from t_dayi where  ");
		
		//查询条件返回页面
		if (dbiaoti != null && !"".equals(dbiaoti)) {

			sb.append(" dbiaoti like '%"+dbiaoti+"%' ");
			sb.append(" and ");
			
			request.setAttribute("dbiaoti", dbiaoti);
		}
		

		sb.append(" 1=1 order by id desc ");
		
		String sql = sb.toString();
		

		//查询列表
		Map<String,List<Dayi>> map = dayiService.selectBeanMap(currentpage,pageSize,url,sql);
		String pagerinfo = map.keySet().iterator().next();
		List<Dayi> list = map.get(pagerinfo);

		//列表返回页面
		request.setAttribute("list", list);

		//分页信息返回页面
		request.setAttribute("pagerinfo", pagerinfo);

		//查询按钮
		request.setAttribute("url", url);

		//添加，更新，删除等按钮
		request.setAttribute("url2", "dayi");

		request.setAttribute("title", "在线答疑管理");


		return "dayi/dayilist.jsp";

	}


	

	//删除操作
	@RequestMapping("/dayidelete.do")
	public void dayidelete(HttpServletResponse response,int id){

		dayiService.deleteBean(id);


		this.getPrintWriter(response).print("<script language=javascript>alert('操作成功');window.location.href='dayilist.do';</script>");
	}
	
	
	//跳转到查看详情页面
	@RequestMapping("/dayishow.do")
	public String dayishow(HttpServletRequest request,int id){

		Dayi bean = dayiService.selectData(" select * from t_dayi where id= "+id).get(0);

		request.setAttribute("bean", bean);

		request.setAttribute("title", "查看详情");

		return "dayi/dayishow.jsp";

	}
	
}












